package com.zeildlin.seecode.Service;

import com.zeildlin.seecode.util.RedisKeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class FollowService {
    @Autowired
    RedisTemplate redisTemplate;

    //关注
    public void follow(int userId, int entityUserId) {
        String entityFollowKey = RedisKeyUtil.getUserFollowKey(entityUserId);
        boolean isMember = redisTemplate.opsForSet().isMember(entityFollowKey, userId);
        if (isMember) {
            redisTemplate.opsForSet().remove(entityFollowKey, userId);
        } else {
            redisTemplate.opsForSet().add(entityFollowKey, userId);
        }
    }

    //查询关注数量
    public long followCount(int entityUserId){
        String entityFollowCount= RedisKeyUtil.getUserFollowKey(entityUserId);
        return redisTemplate.opsForSet().size(entityFollowCount);
    }

}
